package string;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-10-06
 * Time: 11:01
 */
public class Test_CompareTo {
    public static void main(String[] args) {
        String s8 = new String("abc");
        //String s9 = new String("abc");  //0
        String s9=new String("abcdef");  //较短的s8长度为k，s9的前k个与s8相等，后面还有，那么直接返回长度的差值
        //String s9=new String("accdef");  //前k个有与s8不等的地方，直接返回第一个不等的地方的字符的ascii码差值
        System.out.println(s8.compareTo(s9));
        
        /* compareTo源码：
        public int compareTo(String anotherString) {
        int len1 = value.length;
        int len2 = anotherString.value.length;
        int lim = Math.min(len1, len2);
        char v1[] = value;
        char v2[] = anotherString.value;

        int k = 0;
        while (k < lim) {
            char c1 = v1[k];
            char c2 = v2[k];
            if (c1 != c2) {
                return c1 - c2;
            }
            k++;
        }
        return len1 - len2;
       }
        *
        *
         */
    }
}
